<?php

/**
 * 附件上传
 */
namespace Asset\Controller;
use Common\Controller\AdminbaseController;
class AssetController extends AdminbaseController {


    function _initialize() {
    	$adminid=sp_get_current_admin_id();
    	$userid=sp_get_current_userid();
    	if(empty($adminid) && empty($userid)){
    		exit("非法上传！");
    	}
    }
	public  function djhot(){
		return "djhot.mp3";
	} 

    /**
     * swfupload 上传 
     */
    public function swfupload() {
    	$temp=explode(",", I("args"));
		$filetype_post=explode("|", $temp[1]);
		$config=NULL;
		if(empty($temp[1])==FALSE){
			session("file_type",$temp[1]);
		}
	 	 if("mp3"==session("file_type")){
			 $savepath='vidio/';
	 	 	 $config=array(
            		'rootPath' => './'.C("UPLOADPATH"),
            		'savePath' => $savepath,
            		'maxSize' => 11048576,
            		'saveName'=> 'djhot',
            		'exts'       =>   '',
            		'autoSub'    =>false,
            		'replace'=>true,
            );
		   }else{// 图片上传
		  		   $savepath=date('Ymd').'/';
		   	       $config=array(
            		'rootPath' => './'.C("UPLOADPATH"),
            		'savePath' => $savepath,
            		'maxSize' => 11048576,
            		'saveName'=> array("uniqid",""),
            		'exts'       =>   '',
            		'autoSub'    =>false,
            		'replace'=>true,
            );
		 }
		
		$filetype='';
		foreach ($filetype_post as $key => $value) {
			$filetype.="*.".$value.";";
		}
		
		$this->assign('filetype',$filetype."*.zpk");
		
        if (IS_POST) {

            //上传处理类
			$upload = new \Think\Upload($config);
			$info=$upload->upload();
            //开始上传
            if ($info) {
                //上传成功
                //写入附件数据库信息
                $first=array_shift($info);
              
                if(!empty($first['url'])){
                	$url=$first['url'];
                }else{
                	 \Think\Log::write(C("TMPL_PARSE_STRING.__UPLOAD__"));
                	$url=C("TMPL_PARSE_STRING.__UPLOAD__").$savepath.$first['savename'];
                }
				echo "1," . $url.",".'1,'.$first['name'];
				exit;
            } else {
                //上传失败，返回错误
                exit("0," . $upload->getError());
            }
        } else {
            $this->display(':swfupload');
        }
    }

}
